package com.hzqy.service.hotel;

import com.hzqy.persistence.dao.hotel.HotelUserNeedsDao;
import com.hzqy.persistence.dao.hqjc.HqjcDao;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.HotelUserNeedsVo;
import com.hzqy.web.vo.PmsOrgVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HotelUserNeedsServiceBean{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	final private int CATALOG_KFFW = 855;//客房服务
	final private int CATALOG_DCFW = 857;//点餐服务
	final private int CATALOG_GWFW = 859;//购物服务
	final private int CATALOG_TSJY = 861;//投诉建议

	@Resource
	private HotelUserNeedsDao hotelUserNeedsDao;

	@Resource
	private HqjcDao hqjcDao;

	public int insertHotelUserNeedsVo(PmsOrgVo poVo,HotelUserNeedsVo vo) {
		if(poVo!=null){
			vo.setF_hsn_orgId(poVo.getF_po_id());
		}
		vo.setF_hsn_sn(getPrintSN(vo));
		if(vo.getF_hsn_printStatus()==0){
			vo.setF_hsn_printStatus(1);
		}
		//JSONObject jo= (JSONObject) JSONObject.toJSON(vo);
		//PostUtil.postJson("http://localhost:8080/gd_hqjc_admin/itf/xpyunItf/print.do",jo.toString());
		return hotelUserNeedsDao.insertHotelUserNeedsVo(vo);
	}
	public List<CmContentVo> selectCmContentVoForServerid(String f_cc_name) {
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("f_cc_name",f_cc_name);
		return hotelUserNeedsDao.selectCmContentVoForServerid(map);
	}

    /**
     * 	用户需求列表获取
     * @param index
     * @param pageSize
     * @return
     */
    public List<HotelUserNeedsVo> selectHotelUserNeedsList(HotelUserNeedsVo hotelUserNeedsVo, int index,int pageSize) {
        List<HotelUserNeedsVo> results;
        Map<String,Object> map = new HashMap<String, Object>();
        if(index >=0 && pageSize > 0) {
            map.put("firstResult",index);
            map.put("pageSize",pageSize);
            map.put("startTime", hotelUserNeedsVo.getStartTime());
            map.put("endTime", hotelUserNeedsVo.getEndTime());
            map.put("serverid", hotelUserNeedsVo.getServerid());
            map.put("roonNum", hotelUserNeedsVo.getRoonNum());
            map.put("f_hsn_orgId", hotelUserNeedsVo.getF_hsn_orgId());
            map.put("type", hotelUserNeedsVo.getType());
            map.put("status", hotelUserNeedsVo.getStatus());
            map.put("star", hotelUserNeedsVo.getStar());
            map.put("f_hsn_printStatus", hotelUserNeedsVo.getF_hsn_printStatus());
            results = hotelUserNeedsDao.selectHotelUserNeedsList(map);
        } else {
            results= new ArrayList<HotelUserNeedsVo>();
        }
        return results;
    }

	public static void main(String[] args){
		PmsOrgVo poVo = new PmsOrgVo();
		poVo.setF_po_id(59);

		HotelUserNeedsVo hotelUserNeedsVo = new HotelUserNeedsVo();
		hotelUserNeedsVo.setF_hsn_id(123);
		hotelUserNeedsVo.setF_hsn_type(14);
		hotelUserNeedsVo.setF_hsn_detail("鱼一条，肉两块");
		hotelUserNeedsVo.setF_hsn_zxtype("1");
		hotelUserNeedsVo.setF_hsn_roonNum("1002");
		hotelUserNeedsVo.setF_hsn_zxdate("2020-02-02 00:02:02");
		hotelUserNeedsVo.setF_hsn_price(new BigDecimal(120));
		hotelUserNeedsVo.setF_hsn_remarks("瘦肉多一下");
		new HotelUserNeedsServiceBean().insertHotelUserNeedsVo(poVo, hotelUserNeedsVo);
	}

	public String getPrintSN(HotelUserNeedsVo hotelUserNeedsVo){
		String sn = "";
		int f_ccc_catalogid = 0;
		switch (hotelUserNeedsVo.getF_hsn_type()){
			case 1:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 2:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 3:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 4:
				f_ccc_catalogid = CATALOG_TSJY;
				break;
			case 5:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 6:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 7:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 8:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 11:
				f_ccc_catalogid = CATALOG_DCFW;
				break;
			case 12:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 13:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
			case 14:
				f_ccc_catalogid = CATALOG_GWFW;
				break;
			default:
				f_ccc_catalogid = CATALOG_KFFW;
				break;
		}
		//获取sn
//		Map<String,Object> map = new HashMap<String, Object>();
//		map.put("f_ccc_catalogid", f_ccc_catalogid);
//		map.put("f_cc_status",1);
//		map.put("f_cc_companyid", hotelUserNeedsVo.getF_hsn_orgId()+"");
//		map.put("firstResult", 0);
//		map.put("maxResults", 1);
		List<CmContentVo> results = hqjcDao.selectContentListByCatalogId(f_ccc_catalogid,hotelUserNeedsVo.getF_hsn_orgId()+"",0,1,"1",new CmContentVo());
		if(!results.isEmpty()){
			sn = results.get(0).getF_cc_obligate1();
		}
		return sn;
	}
}
